$(function() {
	// 初始化表格商家今日销售排行
	$("#dataTableToday").jqxDataTable({
		width : "100%",
		source : getSource({type:1}),
		pageable : true,
		serverProcessing : true,
		pageSize : 15,
		pagerButtonsCount : 10,
		columnsResize : true,
		sortable : true,
		selectionMode : "singleRow",
		columns : [ {
			text : "序号",
			width : "4%",
			dataField : "id",
			cellsRenderer : function(row) {
				return (row + 1).toString();
			}
		}, {
			text : "商家",
			dataField : "name"
		}, {
			text : "销售额(元)",
			dataField : "sales"
		}, {
			text : "订单数",
			dataField : "count"
		} ],
	});

	// 初始化表格商家总销售排行
	$("#dataTable").jqxDataTable({
		width : "100%",
		source : getSource(),
		pageable : true,
		serverProcessing : true,
		pageSize : 15,
		pagerButtonsCount : 10,
		columnsResize : true,
		sortable : true,
		selectionMode : "singleRow",
		columns : [ {
			text : "序号",
			width : "4%",
			dataField : "id",
			cellsRenderer : function(row) {
				return (row + 1).toString();
			}
		}, {
			text : "商家",
			dataField : "name"
		}, {
			text : "销售额(元)",
			dataField : "sales"
		}, {
			text : "订单数",
			dataField : "count"
		} ],
	});

});

/**
 * 获取数据源
 */
function getSource(json) {
	var url = "/manager/sellerRanking.do?1=1";
	if (json !== undefined) {
		if (json.type !== undefined && json.type !== null && json.type !== "") {
			url += "&type=" + json.type;
		}
	}
	// 设置数据源
	var tableSource = new $.jqx.dataAdapter({
		dataType : "json",
		dataFields : [ {
			name : "name",
			type : "string"
		}, {
			name : "sales",
			type : "double"
		}, {
			name : "count",
			type : "double"
		} ],
		id : "name",
		url : url
	}, {
		formatData : function(data) {
			data.pagenum = data.pagenum + 1;
			return data;
		}
	});
	return tableSource;
}

function formatMoney(money) {
	if (money >= 1000000000) {
		return (money / 100000000).toFixed(2) + "E";
	} else if (money >= 10000000) {
		return (money / 10000000).toFixed(2) + "KW";
	} else if (money >= 1000000) {
		return (money / 10000).toFixed(2) + "W";
	} else if (money >= 100000) {
		return (money / 1000).toFixed(2) + "K";
	} else if (money >= 1000) {
		return "￥" + money.toFixed(1);
	} else {
		return "￥" + money.toFixed(2);
	}
}